package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.annotation.RequiresPermissionsDesc;
import com.cskaoyan.market.bo.CouponListBo;
import com.cskaoyan.market.bo.ListUserBo;
import com.cskaoyan.market.db.domain.MarketCoupon;
import com.cskaoyan.market.db.domain.MarketCouponUser;
import com.cskaoyan.market.service.AdminCouponService;
import com.cskaoyan.market.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/coupon")
public class AdminCouponController {

    @Autowired
    AdminCouponService adminCouponService;

    @GetMapping("listuser")
    public Object listuser(ListUserBo listUserBo) {
        List<MarketCouponUser> couponUserList = adminCouponService.listuser(listUserBo);
        return ResponseUtil.okList(couponUserList);
    }

    @GetMapping("list")
    @RequiresPermissions("admin:coupon:list")
    @RequiresPermissionsDesc(menu = {"推广管理", "优惠券管理"},button = "查询")
    public Object list(CouponListBo couponListBo) {
        List<MarketCoupon> couponList = adminCouponService.list(couponListBo);
        return ResponseUtil.okList(couponList);
    }

    @PostMapping("update")
    @RequiresPermissions("admin:coupon:update")
    @RequiresPermissionsDesc(menu = {"推广管理", "优惠券管理"},button = "编辑")
    public Object update(@RequestBody MarketCoupon coupon) {
        MarketCoupon marketCoupon = adminCouponService.update(coupon);
        return ResponseUtil.ok(marketCoupon);
    }

    @PostMapping("delete")
    @RequiresPermissions("admin:coupon:delete")
    @RequiresPermissionsDesc(menu = {"推广管理", "优惠券管理"},button = "删除")
    public Object delete(@RequestBody MarketCoupon marketCoupon) {
        adminCouponService.delete(marketCoupon.getId());
        return ResponseUtil.ok();
    }

    @PostMapping("create")
    @RequiresPermissions("admin:coupon:create")
    @RequiresPermissionsDesc(menu = {"推广管理", "优惠券管理"},button = "添加")
    public Object create(@RequestBody MarketCoupon marketCoupon) {
        MarketCoupon marketCouponResponse = adminCouponService.insert(marketCoupon);
        return ResponseUtil.ok(marketCouponResponse);
    }
}
